
<form id="formEdit" action="save" class="form-horizontal" role="form">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">操作</h4>
			</div>
			<div class="modal-body">

				<!-- 以下为要修改的的内容 -->
				<input type="hidden" name="id" id="id"
					data-th-value="${model==null?null:model.id}">
				<div class="form-group">
					<label for="txt_year" class="col-sm-2 control-label"><span
						class="text-red">*</span>年级</label>
					<div class="col-sm-9">
						<select id="years" name="year" onchange="xzyear()">
							<option style="display: none;"></option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="txt_profesion" class="col-sm-2 control-label"><span
						class="text-red">*</span>专业</label>
					<div class="col-sm-9">
						<select id="profesioan" name="profesion" onchange="xzprofesion()">
							<option style="display: none;"></option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="txt_tbClass" class="col-sm-2 control-label"><span
						class="text-red">*</span>班级</label>
					<div class="col-sm-9">
						<select id="banji" name="tbclass">
							<option style="display: none;"></option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="txt_username" class="col-sm-2 control-label"><span
						class="text-red">*</span>学号</label>
					<div class="col-sm-9">
						<input type="text" name="username"
							data-th-value=${model==null?null:model.username}
							class="form-control" id="txt_username" placeholder="学号">
					</div>
				</div>
				<div class="form-group">
					<label for="txt_name" class="col-sm-2 control-label"><span
						class="text-red">*</span>姓名</label>
					<div class="col-sm-9">
						<input type="text" name="name"
							data-th-value="${model==null?'':model.name}" class="form-control"
							id="name" placeholder="姓名">
					</div>
				</div>
				<div class="form-group">
					<label for="txt_sex" class="col-sm-2 control-label"><span
						class="text-red">*</span>性别</label>
					<div class="col-sm-9">
						<select id="sex" name="sex">
							<option style="display: none;"></option>
							<option value="男">男</option>
							<option value="女">女</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="txt_phone" class="col-sm-2 control-label">电话</label>
					<div class="col-sm-9">
						<input type="text" name="phone"
							data-th-value="${model==null?null:model.phone}"
							class="form-control" id="txt_phone" placeholder="电话">
					</div>
				</div>
				<div class="form-group">
					<label for="txt_email" class="col-sm-2 control-label">邮箱</label>
					<div class="col-sm-9">
						<input type="text" name="email"
							data-th-value="${model==null?null:model.email}"
							class="form-control" id="txt_email" placeholder="邮箱">
					</div>
				</div>
				<div class="form-group">
					<label for="txt_addrs" class="col-sm-2 control-label">住址</label>
					<div class="col-sm-9">
						<input type="text" name="addrs"
							data-th-value="${model==null?null:model.addrs}"
							class="form-control" id="txt_addrs" placeholder="住址">
					</div>
				</div>
				<div class="form-group">
					<label for="txt_job" class="col-sm-2 control-label">职务</label>
					<div class="col-sm-9">
						<input type="text" name="job"
							data-th-value="${model==null?null:model.job}"
							class="form-control" id="txt_job" placeholder="职务">
					</div>
				</div>

				<!-- 以上为要修改的内容 -->

			</div>
			<div class="modal-footer">
				<button type="submit" class="btn btn-primary">
					<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存
				</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">
					<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭
				</button>
			</div>
		</div>
	</div>
</form>
<style type="text/css">
.text-red {
	color: red;
	font-weight: 600;
	font-size: 18px;
	position: relative;
	top: 3px;
	margin-right: 3px;
	margin-left: 0px;
	padding: 0px;
}

select {
	width: 100%;
	height: 34px;
	background-image: none;
	background-color: #fff;
	color: #555;
	line-height: 1.42857143;
	font-size: 14px;
	padding: 6px 12px;
	border: 1px solid #ccc;
	border-radius: 4px;
}
</style>
<script type="text/javascript" th:inline="javascript">
	/*以下新增需要用到的*/
	$('#years').selectpicker({
		title : '选择年级'
	});
	$('#profesioan').selectpicker({
		title : '选择专业'
	});
	$('#banji').selectpicker({
		title : '选择班级'
	});
	$('#sex').selectpicker({
		title : '选择性别'
	});

	var options = {
		excluded : [':disabled'],	
		message : '验证不通过',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {

			name : {
				validators : {
					notEmpty : {
						message : '姓名不能为空'
					}
				}
			},
			username : {
				validators : {
					notEmpty : {
						message : '学号不能为空'
					},
					regexp : {/* 只需加此键值对，包含正则表达式，和提示 */
						regexp : /^[0-9]*$/,
						message : '学号只能是数字'
					},
					stringLength : {
						min : 6,
						max : 30,
						message : '学号长度必须在6到30之间'
					}
				}
			},
			year : {
				validators : {
					notEmpty : {
						message : '年级不能为空'
					}
				}
			},
			profesion : {
				validators : {
					notEmpty : {
						message : '专业不能为空'
					}
				}
			},
			tbclass : {
				validators : {
					notEmpty : {
						message : '班级不能为空'
					}
				}
			},
			sex : {
				validators : {
					notEmpty : {
						message : '性别不能为空'
					}
				}
			},
			phone : {
				validators : {
						regexp : {
							regexp : /^[1][3,4,5,7,8][0-9]{9}$/,
							message : '请输入正确的手机号码'
						}
				}
			},
			email : {
				validators : {
					emailAddress : {
						message : '请输入正确的邮件地址如：123@qq.com'
					}
				}
			}
		}
	};
	$('#formEdit').bootstrapValidator(options).on('success.form.bv',
			function(e) {
				e.preventDefault(); //很重要没有它则会提交默认表单，不会做下面的ajax表单提交
				var fd = new FormData($("#formEdit")[0]);
				$.ajax({
					url : "student/save",
					type : "POST",
					data : fd,
					processData : false, // 不处理数据  
					contentType : false, // 不设置内容类型
					success : function(result) {
						if (result.success) {
							$('#myModal').modal("hide");
						} else {
							bootbox.alert(result.msg);
						}
					},
					error : function(result) {
						alert(result);
					}
				});
			});
</script>
<script type="text/javascript">
	$(function() {
		var sex = '[[${model==null?null:model.sex}]]';
		$('#sex').selectpicker('val', sex);
		$('#sex').selectpicker('refresh');

		//页面加载时把所有年级加载到页面
		$.post('student/year',
						function(data) {
							for (var i = 0; i < data.length; i++) {
								$('#years').append("<option value=" + data[i] + "> "+ data[i] + "</option>");
							}
							$('#years').selectpicker('refresh');
							var model = '[[${model}]]';
							if (model != null && model != ''&& model != undefined) {
								var year = '[[${model==null?null:model.tbClass.profession.year}]]';
								$('#years').selectpicker('val', year);
								xzyear();
							} else {
								var shearchyear = $('#shearchyear').val();
								if (shearchyear != null && shearchyear != undefined) {
									$('#years').selectpicker('val', shearchyear);
									xzyear();
								}
							}
						});
	});

	//当年级发生改变时专业的数据从后台加载
	function xzyear() {
		var year = $('#years').val();//取年级
		$('#profesioan').empty();//加载数据前把专业下拉框制空
		$.post('student/profesion',{year : year},
						function(data) {
							for (var i = 0; i < data.length; i++) {
								$('#profesioan').append("<option value=" + data[i].profesion + "> "+ data[i].profesion+ "</option>");
							}
							
							$('#profesioan').selectpicker('refresh');
							var model = '[[${model}]]';
							if (model != null && model != ''&& model != undefined) {
								var profesioan = '[[${model==null?null:model.tbClass.profession.profesion}]]';
								$('#profesioan').selectpicker('val', profesioan);
								xzprofesion();
							} else {
								var shearchprofesion = $('#profesionId').val();
								if (shearchprofesion != null && shearchprofesion != undefined) {
									$('#profesioan').selectpicker('val', shearchprofesion);
									xzprofesion();
								}
							}
						});
	};

	//当年级和专业发生改变时班级的数据从后台加载
	function xzprofesion() {
		var year = $('#years').val();//取年级
		var profesion = $('#profesioan').val();//取专业
		$('#banji').empty();//加载数据前把班级下拉框制空
		$.post('student/tbClass', {
			year : year,
			profesion : profesion
		}, function(data) {
			for (var i = 0; i < data.length; i++) {
				$('#banji').append(
						"<option value=" + data[i].name + "> " + data[i].name
								+ "</option>");
			}
			$('#banji').selectpicker('refresh');
			var model = '[[${model}]]';
			if (model != null && model != ''&& model != undefined) {
				var banji = '[[${model==null?null:model.tbClass.name}]]';
				$('#banji').selectpicker('val', banji);
			}else{
				var shearchtbClass = $('#tbClass').val();
				if (shearchtbClass != null && shearchtbClass != undefined) {
					$('#banji').selectpicker('val', shearchtbClass);
				}
			}
		});
	};
</script>